package test.netty.server;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author cuichao
 * @Description: ClientEncode
 * @Date: create in 2020/12/21 14:58
 */
public class ServerEncode extends MessageToByteEncoder<String> {
    @Override
    protected void encode(ChannelHandlerContext ctx, String msg, ByteBuf out) throws Exception {
        byte[] bytes = msg.getBytes();
        out.writeInt(bytes.length);
        out.writeBytes(bytes);
    }
}
